package cn.chengdu.controller;


import cn.chengdu.entity.Staffinfo;
import cn.chengdu.service.IStaffinfoService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.data.redis.core.RedisTemplate;
import org.springframework.data.redis.core.ValueOperations;
import org.springframework.stereotype.Controller;
import org.springframework.ui.Model;
import org.springframework.web.bind.annotation.RequestMapping;

import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.ResponseBody;
import org.springframework.web.bind.annotation.RestController;
import org.springframework.web.servlet.ModelAndView;

import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import javax.servlet.http.HttpSession;
import java.util.Date;
import java.text.SimpleDateFormat;
import java.util.List;

/**
 * <p>
 * 医院员工信息表 前端控制器
 * </p>
 *
 * @author jobob
 * @since 2019-11-25
 */
@Controller
@RequestMapping("/staffinfo")
public class StaffinfoController {
    @Autowired
    private IStaffinfoService iStaffinfoService;

    @Autowired
    private RedisTemplate redisTemplate;
    private static int i = 1;

    @RequestMapping("/doctor")
    @ResponseBody
    public  List<Staffinfo> getdoctor(@RequestParam("depid")int depids, HttpServletRequest request){
        ValueOperations<String,Integer> operations=redisTemplate.opsForValue();
        operations.set("depid",depids);

       List<Staffinfo> list= iStaffinfoService.getdoctors(depids);

       return list;
    }




    @RequestMapping("/xiangqing")
    @ResponseBody
     public List<Staffinfo> getdoctor( HttpServletRequest request){

        ValueOperations<String,Integer> operations=redisTemplate.opsForValue();
        System.out.println("详情:"+operations.get("id"));


//      获取医生信息详情

        int depid=operations.get("depid");
        List<Staffinfo> list=iStaffinfoService.getdoctors(depid);


        System.out.println(list);
        return list;
    }
    @RequestMapping("/yueyue")
    @ResponseBody
    public String  yueyue( HttpServletRequest request){
        return "null";
    }

    @RequestMapping("/redis")
    @ResponseBody
    public boolean redis() {
        SimpleDateFormat df = new SimpleDateFormat("yyyy-MM-dd");//设置日期格式
        String nowDate= df.format(new Date());
        ValueOperations<String,String> operations=redisTemplate.opsForValue();
//            判断存储日期是否是今天日期
            if(operations.get("nowDate").equals(nowDate)){
                System.out.println("等于："+operations.get("nowDate"));
                return true;
            }else{
                operations.set("nowDate",nowDate);
                System.out.println("不等于："+operations.get("nowDate"));
                return true;
            }



//        i++;
    }


}
